package ie.dit.reg08.main;

import ie.dit.reg08.attSelector.Selector;
import ie.dit.reg08.manager.*;
import ie.dit.reg08.realiser.CaseBasedSentenceGenerator;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;

public class Main {

	static final String TRAININGCORPUS = "./REG-Challenge-Pack/Training-Data/TUNA/train";
	//static final String TESTCORPUSTASK2 = "./REG-Challenge-Pack/Training-Data/TUNA/train";	   
	static final String TESTCORPUSTASK2 = "./output/task1";
	static final String OUTPUTDIRTASK1 = "./output/task1";
	static final String OUTPUTDIRTASK2 = "./output/task2";
	
	public static void main(String argv[]) {
		
		System.out.println("b's version");
		System.out.println("**************************************************");
		System.out.println("* DIT REG '08 Entry");
		System.out.println("**************************************************");
		System.out.println();
		
		// Create the corpusManager to deal with loading and saving data files
		CorpusIOManager p = new CorpusIOManager();
		
		System.out.print("Loading training corpus....");

		// Load the training data
		Vector<Trial> trainingTrials = p.processCorpus(TRAININGCORPUS);
		
		System.out.println(trainingTrials.size() + " trials loaded.");
		
		System.out.println("**Task 1: Attribute Selection ***********************");

		Selector s = new Selector(trainingTrials);
		
		Vector<greInterface> vSysAttSets = s.selectAttributes();

		System.out.println(vSysAttSets.size() + " experiments performed.");
		
		System.out.print("Outputting xml results to " + OUTPUTDIRTASK1 + "....");
		
		// Output the XML generated from the experiment objects
		p.outputDescriptions(OUTPUTDIRTASK1, vSysAttSets);
		
		System.out.println("**Task 2: Sentence Generation***********************");
				
		System.out.print("Loading task 2 testing corpus....");
		
		// Load the task 2 test data
		Vector<Trial> testTrialsTask2 = p.processCorpus(TESTCORPUSTASK2);

		System.out.println(testTrialsTask2.size() + " trials loaded.");
		
		System.out.print("Performing sentence generation experiments....");
		
		// Create a new empty vector of experiments
		Vector<greInterface> sentenceGenerationExperiments = new Vector<greInterface>();
		
		// cycle through the task 2 test data and create an experiment for each trial
		Iterator<Trial> i = testTrialsTask2.iterator();
		while(i.hasNext()) {
			sentenceGenerationExperiments.add(new CaseBasedSentenceGenerator(trainingTrials, i.next()));
		}
		
		System.out.println(sentenceGenerationExperiments.size() + " experiments performed.");
		
		System.out.print("Outputting xml results to " + OUTPUTDIRTASK2 + "....");
		
		// Output the XML generated from the experiment objects
		p.outputDescriptions(OUTPUTDIRTASK2, sentenceGenerationExperiments);
		
		System.out.println(sentenceGenerationExperiments.size() + " xml files output.");
		
		System.out.println("**************************************************");
		System.out.println("*              FINISHED PROCESSING               *");
		System.out.println("**************************************************");

	}
}
